package com.micro.repository;

import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.micro.entity.HotelOrder;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;

import java.time.LocalDate;
import java.util.List;

@Mapper
public interface HotelOrderRepository extends BaseMapper<HotelOrder> {
    
    // 根据用户ID查询订单
    @Select("SELECT 订单id, 用户ID, 酒店ID, 入住日期, 退房日期, 订单状态, 支付金额, 支付方式, 支付时间, 退款金额, 退款时间, 更新时间, 过期时间 FROM 酒店订单 WHERE 用户ID = #{userId}")
    @Results({
        @Result(property = "orderId", column = "订单id"),
        @Result(property = "userId", column = "用户ID"),
        @Result(property = "hotelId", column = "酒店ID"),
        @Result(property = "checkInDate", column = "入住日期"),
        @Result(property = "checkOutDate", column = "退房日期"),
        @Result(property = "orderStatus", column = "订单状态"),
        @Result(property = "paymentAmount", column = "支付金额"),
        @Result(property = "paymentMethod", column = "支付方式"),
        @Result(property = "paymentTime", column = "支付时间"),
        @Result(property = "refundAmount", column = "退款金额"),
        @Result(property = "refundTime", column = "退款时间"),
        @Result(property = "updateTime", column = "更新时间"),
        @Result(property = "expireTime", column = "过期时间")
    })
    List<HotelOrder> findByUserId(@Param("userId") Long userId);
    
    // 根据酒店ID查询订单
    @Select("SELECT * FROM 酒店订单 WHERE 酒店ID = #{hotelId}")
    List<HotelOrder> findByHotelId(@Param("hotelId") Long hotelId);
    
    // 根据订单状态查询订单
    @Select("SELECT * FROM 酒店订单 WHERE 订单状态 = #{orderStatus}")
    List<HotelOrder> findByOrderStatus(@Param("orderStatus") String orderStatus);
    
    // 根据入住日期查询订单
    @Select("SELECT * FROM 酒店订单 WHERE 入住日期 = #{checkInDate}")
    List<HotelOrder> findByCheckInDate(@Param("checkInDate") LocalDate checkInDate);
    
    // 根据退房日期查询订单
    @Select("SELECT * FROM 酒店订单 WHERE 退房日期 = #{checkOutDate}")
    List<HotelOrder> findByCheckOutDate(@Param("checkOutDate") LocalDate checkOutDate);
    
    // 根据用户ID和订单状态查询订单
    @Select("SELECT * FROM 酒店订单 WHERE 用户ID = #{userId} AND 订单状态 = #{orderStatus}")
    List<HotelOrder> findByUserIdAndOrderStatus(@Param("userId") Long userId, @Param("orderStatus") String orderStatus);
    
    // 根据酒店ID和入住日期范围查询订单
    @Select("SELECT * FROM 酒店订单 WHERE 酒店ID = #{hotelId} AND 入住日期 BETWEEN #{startDate} AND #{endDate}")
    List<HotelOrder> findByHotelIdAndCheckInDateBetween(@Param("hotelId") Long hotelId, 
                                                       @Param("startDate") LocalDate startDate, 
                                                       @Param("endDate") LocalDate endDate);
}
